#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | sed 's/^Version: \([^+]*\).*/\1/')
DISTRO := $(shell dpkg-parsechangelog | egrep '^Distribution:' | sed 's/^Distribution: \([^+]*\).*/\1/')
REPORTBUG_VERSION := $(shell python -c "import reportbug; print reportbug.VERSION_NUMBER")

%:
	dh $@ --with=python2

override_dh_auto_build:
	# Test if versions are synchronized (only if releasing); this will bomb if not synced
	if [ "$(DISTRO)" != "UNRELEASED" -a "$(REPORTBUG_VERSION)" != "$(VERSION)" ] ; \
	then \
		echo 'Please update VERSION_NUMBER variable in reportbug/__init__.py'; exit 1 ; \
	fi

	python setup.py build

override_dh_auto_install:
	python setup.py install --root $(CURDIR)/debian/reportbug --install-layout=deb
	mv $(CURDIR)/debian/reportbug/usr/lib $(CURDIR)/debian/python-reportbug/usr
	chmod 0755 $(CURDIR)/debian/reportbug/usr/bin/*
	cp -p conf/reportbug.conf $(CURDIR)/debian/reportbug/etc

	cp -p debian/desktop $(CURDIR)/debian/reportbug/usr/share/applications/reportbug.desktop

override_dh_installman:
	dh_installman man/*
